<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->bigInteger('asset_id')->index()->comment('发行平台资产ID');
            $table->string('type', 16)->default(\App\Enums\ProductType::ISSUE)->comment('商品类型: 发行/转售/肓盒');
            $table->string('name', 64)->comment('商品名称');
            $table->string('logo_url', 256)->comment('LOGO图片地址');
            $table->string('public_hash', 64)->comment('公示Hash');
            $table->string('contract_address', 64)->index()->comment('合约地址');
            $table->integer('issue_count')->comment('发行数量');
            $table->integer('left_count')->comment('剩余数量');
            $table->integer('sales_count')->default(0)->comment('销售数量');
            $table->string('publisher_account', 16)->index()->comment('发行者账号');
            $table->integer('price')->comment('发行价格, 单位:分');
            $table->string('intro', 512)->nullable()->comment('商品简介');
            $table->text('description')->nullable()->comment('商品描述');
            $table->bigInteger('resale_user_id')->default(0)->index()->comment('转售商品的用户ID');
            $table->bigInteger('category_id')->default(0)->index()->comment('自定义分类ID');
            $table->bigInteger('agent_id')->default(0)->index()->comment('所属代理');
            $table->dateTime('online_time')->nullable()->comment('商品上线时间');
            $table->dateTime('start_time')->nullable()->comment('商品开始销售时间');
            $table->dateTime('end_time')->nullable()->comment('商品结束销售时间');
            $table->integer('buy_limit')->default(-1)->comment('商品购买数量限制, -1表示不限购');
            $table->tinyInteger('recommend_flag')->default(0)->comment('推荐标记, 0表示不推荐');
            $table->string('status', 16)->comment('商品状态');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
